using System;
using System.Web.UI;


public partial class admin_default : SiteAdminBasePage
{
    public static string rootPath = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        
        rootPath = Page.ResolveUrl("~");

        if (!IsPostBack)
        {
            //Populate Chart Data Code
            /*
            #region Initial Variables for Chart
            int count1 = 0, count2 = 0, count3 = 0, count4 = 0, count11 = 0, count21 = 0, count31 = 0, count41 = 0;
            string condition = string.Empty, month1 = string.Empty, month2 = string.Empty, month3 = string.Empty, month4 = string.Empty, year1 = string.Empty, year2 = string.Empty, year3 = string.Empty, year4 = string.Empty;

            month1 = DateTime.Now.AddMonths(-3).ToString("MMMM");
            month2 = DateTime.Now.AddMonths(-2).ToString("MMMM");
            month3 = DateTime.Now.AddMonths(-1).ToString("MMMM");
            month4 = DateTime.Now.ToString("MMMM");

            year1 = DateTime.Now.AddMonths(-3).ToString("yyyy");
            year2 = DateTime.Now.AddMonths(-2).ToString("yyyy");
            year3 = DateTime.Now.AddMonths(-1).ToString("yyyy");
            year4 = DateTime.Now.ToString("yyyy");
            #endregion
            #region Products
            CustomCollection<TblProduct> products = TblProduct.GetAllTblProduct();
            ChartProducts.Width = 430;
            ChartProducts.Height = 296;
            ChartProducts.RenderType = RenderType.ImageTag;
            ChartProducts.Palette = ChartColorPalette.BrightPastel;
            ChartProducts.BorderSkin.SkinStyle = BorderSkinStyle.None;
            ChartProducts.BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
            ChartProducts.BorderlineDashStyle = ChartDashStyle.NotSet;
            ChartProducts.BorderWidth = 2;

            ChartProducts.ChartAreas.Add("Total Products");
            // create a couple of series
            ChartProducts.Series.Add("Products(" + products.Count + ")");

            for (int i = 0; i < products.Count; i++) 
            {
                if (products[i].IsActive == true)
                {
                    if (products[i].CreateDate.ToString("MMMM") == month1 && products[i].CreateDate.ToString("yyyy") == year1)
                    {
                        count1 = count1 + 1;
                    }
                    else if (products[i].CreateDate.ToString("MMMM") == month2 && products[i].CreateDate.ToString("yyyy") == year2)
                    {
                        count2 = count2 + 1;
                    }
                    else if (products[i].CreateDate.ToString("MMMM") == month3 && products[i].CreateDate.ToString("yyyy") == year3)
                    {
                        count3 = count3 + 1;
                    }
                    else if (products[i].CreateDate.ToString("MMMM") == month4 && products[i].CreateDate.ToString("yyyy") == year4)
                    {
                        count4 = count4 + 1;
                    }
                }
            }
            // add points to series 1
            ChartProducts.Series[0].Points.AddXY(month1 + " " + year1, count1);
            ChartProducts.Series[0].Points.AddXY(month2 + " " + year2, count2);
            ChartProducts.Series[0].Points.AddXY(month3+ " " + year3, count3);
            ChartProducts.Series[0].Points.AddXY(month4 + " " + year4, count4);           
            #endregion
            #region Sales

            ChartSales.Width = 430;
            ChartSales.Height = 296;
            ChartSales.RenderType = RenderType.ImageTag;
            ChartSales.Palette = ChartColorPalette.BrightPastel;
            ChartSales.BorderSkin.SkinStyle = BorderSkinStyle.None;
            ChartSales.BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
            ChartSales.BorderlineDashStyle = ChartDashStyle.NotSet;
            ChartSales.BorderWidth = 2;

            ChartSales.ChartAreas.Add("Total Sales");
            ChartSales.Series.Add("Success");
            ChartSales.Series.Add("Failure");
            //ChartSales.Series[0].IsValueShownAsLabel = true;
            //ChartSales.Series[1].IsValueShownAsLabel = true;

            condition = " CONVERT(DATETIME,CreateDate,103)>='" + ECommerce.Library.ECommerce.Utility.FormatDateTime(DateTime.Now.AddMonths(-3), '/') + "'";
            CustomCollection<TblProductPurchaseOrder> purchaseOrders = TblProductPurchaseOrderExtended.GetBackendProductPurchaseOrderListByCondition(condition, "OrderId", 0, 999999);
            count1 = 0; count2 = 0; count3 = 0; count4 = 0;
            count11 = 0; count21 = 0; count31 = 0; count41 = 0;
            for (int i = 0; i < purchaseOrders.Count; i++)
            {
                if (purchaseOrders[i].OrderStatus == "CCSuccess" || purchaseOrders[i].OrderStatus == "ManualAuthorization")
                {
                    if (purchaseOrders[i].CreateDate.ToString("MMMM") == month1 && purchaseOrders[i].CreateDate.ToString("yyyy") == year1)
                    {
                        count1 = count1 + 1;
                    }
                    else if (purchaseOrders[i].CreateDate.ToString("MMMM") == month2 && purchaseOrders[i].CreateDate.ToString("yyyy") == year2)
                    {
                        count2 = count2 + 1;
                    }
                    else if (purchaseOrders[i].CreateDate.ToString("MMMM") == month3 && purchaseOrders[i].CreateDate.ToString("yyyy") == year3)
                    {
                        count3 = count3 + 1;
                    }
                    else if (purchaseOrders[i].CreateDate.ToString("MMMM") == month4 && purchaseOrders[i].CreateDate.ToString("yyyy") == year4)
                    {
                        count4 = count4 + 1;
                    }
                }
                else 
                {
                    if (purchaseOrders[i].CreateDate.ToString("MMMM") == month1 && purchaseOrders[i].CreateDate.ToString("yyyy") == year1)
                    {
                        count11 = count11 + 1;
                    }
                    else if (purchaseOrders[i].CreateDate.ToString("MMMM") == month2 && purchaseOrders[i].CreateDate.ToString("yyyy") == year2)
                    {
                        count21 = count21 + 1;
                    }
                    else if (purchaseOrders[i].CreateDate.ToString("MMMM") == month3 && purchaseOrders[i].CreateDate.ToString("yyyy") == year3)
                    {
                        count31 = count31 + 1;
                    }
                    else if (purchaseOrders[i].CreateDate.ToString("MMMM") == month4 && purchaseOrders[i].CreateDate.ToString("yyyy") == year4)
                    {
                        count41 = count41 + 1;
                    }
                }

            }

            ChartSales.Series[0].Points.AddXY(month1 + " " + year1, count1);
            ChartSales.Series[0].Points.AddXY(month2 + " " + year2, count2);
            ChartSales.Series[0].Points.AddXY(month3 + " " + year3, count3);
            ChartSales.Series[0].Points.AddXY(month4 + " " + year4, count4);

            ChartSales.Series[1].Points.AddXY(month1 + " " + year1, count11);
            ChartSales.Series[1].Points.AddXY(month2 + " " + year2, count21);
            ChartSales.Series[1].Points.AddXY(month3 + " " + year3, count31);
            ChartSales.Series[1].Points.AddXY(month4 + " " + year4, count41);

            #endregion
            #region Registration

            ChartRegistrationMonth.Palette = ChartColorPalette.SeaGreen;
            ChartRegistrationMonth.ChartAreas.Add("Users/Month");
            ChartRegistrationMonth.Series.Add("Users/Month");

            ChartRegistrationPerWeek.Palette = ChartColorPalette.Excel;
            ChartRegistrationPerWeek.ChartAreas.Add("Users / Week");
            ChartRegistrationPerWeek.Series.Add("Users/ Week");

            condition = "IsActive=1 and IsDeleted=0 and CONVERT(DATETIME,CreateDate,103)>='" + ECommerce.Library.ECommerce.Utility.FormatDateTime(DateTime.Now.AddMonths(-4), '/') + "'";
            CustomCollection<TblUser> users = TblUserExtended.GetUserByCondition(condition);
            count1 = 0; count2 = 0; count3 = 0; count4 = 0;
            for (int i = 0; i < users.Count; i++) 
            {
                if (users[i].CreateDate.ToString("MMMM") == month1 && users[i].CreateDate.ToString("yyyy") == year1)
                {
                    count1 = count1 + 1;
                }
                else if (users[i].CreateDate.ToString("MMMM") == month2 && users[i].CreateDate.ToString("yyyy") == year2)
                {
                    count2 = count2 + 1;
                }
                else if (users[i].CreateDate.ToString("MMMM") == month3 && users[i].CreateDate.ToString("yyyy") == year3)
                {
                    count3 = count3 + 1;
                }
                else if (users[i].CreateDate.ToString("MMMM") == month4 && users[i].CreateDate.ToString("yyyy") == year4)
                {
                    count4 = count4 + 1;
                }
            }

            ChartRegistrationMonth.Series[0].Points.AddXY(month1 + " " + year1, count1);
            ChartRegistrationMonth.Series[0].Points.AddXY(month2 + " " + year2, count2);
            ChartRegistrationMonth.Series[0].Points.AddXY(month3 + " " + year3, count3);
            ChartRegistrationMonth.Series[0].Points.AddXY(month4 + " " + year4, count4);
            condition = "IsActive=1 and IsDeleted=0 and CONVERT(DATETIME,CreateDate,103)>='" + ECommerce.Library.ECommerce.Utility.FormatDateTime(DateTime.Now.AddDays(-28), '/') + "' and CONVERT(DATETIME,CreateDate,103)<='" + ECommerce.Library.ECommerce.Utility.FormatDateTime(DateTime.Now.AddDays(-21), '/') + "'";
            users =TblUserExtended.GetUserByCondition(condition);
            ChartRegistrationPerWeek.Series[0].Points.AddXY("Week 1", users.Count);
            
            condition = "IsActive=1 and IsDeleted=0 and CONVERT(DATETIME,CreateDate,103)>='" + ECommerce.Library.ECommerce.Utility.FormatDateTime(DateTime.Now.AddDays(-21), '/') + "' and CONVERT(DATETIME,CreateDate,103)<='" + ECommerce.Library.ECommerce.Utility.FormatDateTime(DateTime.Now.AddDays(-14), '/') + "'";
            users = TblUserExtended.GetUserByCondition(condition);
            ChartRegistrationPerWeek.Series[0].Points.AddXY("Week 2", users.Count);
            
            condition = "IsActive=1 and IsDeleted=0 and CONVERT(DATETIME,CreateDate,103)>='" + ECommerce.Library.ECommerce.Utility.FormatDateTime(DateTime.Now.AddDays(-14), '/') + "' and CONVERT(DATETIME,CreateDate,103)<='" + ECommerce.Library.ECommerce.Utility.FormatDateTime(DateTime.Now.AddDays(-7), '/') + "'";
            users = TblUserExtended.GetUserByCondition(condition);
            ChartRegistrationPerWeek.Series[0].Points.AddXY("Week 3", users.Count);
            
            condition = "IsActive=1 and IsDeleted=0 and CONVERT(DATETIME,CreateDate,103)>='" + ECommerce.Library.ECommerce.Utility.FormatDateTime(DateTime.Now.AddDays(-7), '/') + "' and CONVERT(DATETIME,CreateDate,103)<='" + ECommerce.Library.ECommerce.Utility.FormatDateTime(DateTime.Now, '/') + "'";
            users = TblUserExtended.GetUserByCondition(condition);
            ChartRegistrationPerWeek.Series[0].Points.AddXY("Week 4", users.Count);

            #endregion
            #region Coupons

            CustomCollection<TblCoupon> coupons = TblCoupon.GetAllTblCoupon();
            count1 = 0;
            count2 = 0;
            
            for (int i = 0; i < coupons.Count; i++) 
            {
                if (coupons[i].ExpireDate >= DateTime.Now && coupons[i].IsDeleted == false) 
                {
                    count1 = count1 + 1;
                }
                else if (coupons[i].ExpireDate < DateTime.Now && coupons[i].IsDeleted == false) 
                {
                    count2 = count2 + 1;
                }
            }
            //ChartCoupons.Palette = ChartColorPalette.SeaGreen;
            string[] xValues = { "Active", "Expire"};

            int[] yValues = { count1, count2};
            ChartCoupons.Series["Series1"].Points.DataBindXY(xValues, yValues);
            ChartCoupons.Series["Series1"].Points.DataBindXY(xValues, yValues);
            ChartCoupons.Palette = ChartColorPalette.BrightPastel;
            //Set the chart type
            ChartCoupons.Series["Series1"].ChartType = SeriesChartType.Pie;// Set the bar width
            ChartCoupons.Series["Series1"]["PointWidth"] = "0.5";// Show data points labels
            ChartCoupons.Series["Series1"].IsValueShownAsLabel = true;// Set data points label style
            ChartCoupons.Series["Series1"]["BarLabelStyle"] = "Center";// Show chart as 3D
            ChartCoupons.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;// Draw chart as 3D Cylinder
            ChartCoupons.Series["Series1"]["DrawingStyle"] = "Cylinder";
            if (count1> 0 && count2 > 0)
            {
                ChartCoupons.Series["Series1"].Points[1]["Exploded"] = "true";
            }
           
            #endregion

            */
        }
         
    }
}
